using System;
using System.Collections.Generic;
using System.Linq;
using OS.Infrastructure.Domain;
using OS.Infrastructure.NHibernate;
using OS.Infrastructure.NHibernate.Repositories;
using TaskKernel.Domain.Interface;

namespace TaskKernel.Domain.Nhibernate.NHibernateLayer
{
    public class QueryAccount :  BaseRepository<Account>,  IQueryAccount
    {
        public QueryAccount(ISessionProvider sessionProvider, ILinqProvider linqProvider)
            : base(sessionProvider, linqProvider)
        {
        }
     
        #region IQueryAccount Members

        public virtual Account Get(string login)
        {
            return FindBy(x => x.Login == login && !x.Fired);
        }

        public virtual Account Get(Guid id)
        {
            return FindBy(x => x.UID == id);
        }

        public virtual IEnumerable<Account> GetAccountListBySearchWord(string word)
        {
            return (FilterBy(x => x.FullName.Contains(word)).Where(x => !x.Fired))
                .OrderBy(x => x.FullName);
        }

        public IEnumerable<Account> GetAllNotFiredAccounts()
        {
            return FilterBy(x => !x.Fired).OrderBy(x => x.FullName);
        }

        public IEnumerable<Account> GetAllAccounts()
        {
            return All().OrderBy(x => x.FullName);
        }

        #endregion
    }
}